import SCUMMCore.*;
/*
This class implements the depth handles. This means that handles
the way the objects overlaps based on his position in the screen
*/

class DepthAndScaleEngine.DepthHandler{
	var ArrObjects:Array;
	
	public function DepthHandler(){
		this.ArrObjects = new Array();
	}
	public function addObjectToArrange(pObject:MovieClip){
		this.ArrObjects.push(pObject);
	}
	function rearrangeDepths() {
		var i:Number, j:Number;
		var mc:MovieClip;
		this.ArrObjects.sort(compare);
			for (i = 0; i < this.ArrObjects.length; i++) {
				for(j=i+1;j<this.ArrObjects.length;j++){
					if (this.ArrObjects[i].getDepth() > this.ArrObjects[j].getDepth()) {
						this.ArrObjects[i].swapDepths(this.ArrObjects[j]);
					}
				}
		}
	}
	
	function compare(a:MovieClip, b:MovieClip):Number {
		return a._y - b._y;
	}
}